<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php $this->load->view('common/head'); ?>

<?php $this->load->view('common/header'); ?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar'); ?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs'); ?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set'); ?>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <form class="form-inline" action="" method="get">
                            <label class="inline">用户搜索</label>
                            <select name="field" class="form-control">
                                <option value="user">用户名</option>
                                <option value="phone">电话</option>
                            </select>
                            <input type="text" name="keyword" value="" class="form-control">
                            <label class="inline">&nbsp;&nbsp;排序：</label>
                            <select name="order" class="form-control">
                                <option value="asc">注册时间升</option>
                                <option value="desc">注册时间降</option>
                            </select>
                            <button type="submit" class="btn btn-purple btn-sm">
                                <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                                查询
                            </button>
                            <span class="btn btn-purple btn-sm" id="adduser">
                                <span class="ace-icon fa fa-user icon-on-right bigger-110"></span>
                                新增系统用户
                            </span>
                        </form>
                    </div>
                    <div class="col-xs-12" style="margin-top: 20px;">
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>用户名</th>
                                <th>用户组</th>
                                <th class="center">性别</th>
                                <th>电话</th>
                                <th class="center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (isset($users)) {
                                foreach ($users as $key => $val) { ?>
                                    <tr>
                                        <td><?php echo $val['user_name']; ?></td>
                                        <td class="grouptd">
                                            <span class="group"
                                                  val="<?php echo $val['user_id']; ?>" <?php if ($val['user_group'] == 3) {
                                                echo 'style="color:red"';
                                            } ?>><?php echo $val['title']; ?></span>
                                        </td>
                                        <td class="center"><?php if ($val['user_sex'] == 1) {
                                                echo '男';
                                            } elseif ($val['user_sex'] == 2) {
                                                echo '女';
                                            } else {
                                                echo '保密';
                                            } ?></td>
                                        <td><?php echo $val['user_tel']; ?></td>
                                        <td class="center">
                                            <a href="<?php echo site_url(X_URL . 'member/edit/' . $val['user_id']); ?>">修改</a>&nbsp;
                                            <?php if ($val['user_id'] != 1) { ?>
                                                <a class="del" href="javascript:;"
                                                   val="<?php echo site_url(X_URL . 'member/del'); ?>"
                                                   user="<?php echo $val['user_id']; ?>"
                                                   name="<?php echo $val['user_name']; ?>" title="删除">删除</a>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                <?php }
                            } ?>
                            </tbody>
                        </table>
                        <?php if ($pagination) { ?>
                            <ul class="pagination"><?php echo $pagination; ?></ul><?php } ?>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div><!-- /.main-content -->

        </div><?php $this->load->view('common/footer'); ?>
    

    <?php $this->load->view('common/footerjs'); ?>
    <!-- inline scripts related to this page -->
    <script type="text/javascript">

        $(function () {
            $("#officialnews ul").html('<div class="ace-icon fa fa-spinner fa-spin orange"></div>');
        })
        $("#adduser").click(function () {
            window.location.href = "add";
        });
        $(".del").click(function () {
            var url = $(this).attr('val');
            var user_name = $(this).attr('name');
            var user_id = $(this).attr('user');
            layer.confirm('您确定要删除 ' + user_name + ' 么？', {
                btn: ['删除', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: "post",
                    url: url,
                    data: {'user_id': user_id, 'csrf_test_name': ci_csrf_token()},
                    dataType: "JSON",
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1,
                                icon: 1
                            }, function () {
                                window.location.reload();
                            });
                        } else {
                            layer.msg(msg.info, {
                                time: 1000, //1s后自动关闭
                                shade: 0.1
                            });
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });

    </script>
</body>
</html>
